home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LIFER__ / PROTO / P / PA_LIFE_.C < prev    next >
Text File  |  1991-07-23  |  5KB  |  130 lines

  1. /*  PA_Life_Alert                                                           Handle this alert */
  2.  
  3. /* File name:  PA_Life_Alert.c   */
  4. /* Function:  Handle this alert. */
  5. /* This is a NOTE alert, it is used to inform the user of some general information. */
  6. /* This alert is not used if there is a possibility of losing any data. */
  7. /* This alert is called when:    */
  8. /*     */
  9. /* The choices in this alert allow for:    */
  10. /*     */
  11. /* History: 7/23/91 Original by Prototyper 3.0   */
  12.  
  13.  
  14. #include "PCommonLife.h"    /* Common */
  15. #include "Common_Life.h"    /* Common */
  16. #include "PUtils_Life.h"    /* General Utilities */
  17. #include "Utils_Life.h"    /* General Utilities */
  18.  
  19. #include "PA_Life_Alert.h"    /* This file */
  20. #include "Life_Alert.h"    /* Users specific file */
  21.  
  22. static Boolean    FirstTime;                                                /* Flag for first time thru the filter */
  23.  
  24. /* Prototype for filter routine */
  25. static pascal Boolean MyFilter (DialogPtr theDialog,EventRecord *theEvent,short *itemHit);
  26.  
  27.  
  28.  
  29. /* ======================================================= */
  30.  
  31. /* Filter routine, also used for initial setup of dimmed states */
  32.  
  33. static pascal Boolean MyFilter (theDialog,theEvent,itemHit)
  34. DialogPtr    theDialog;
  35. EventRecord        *theEvent;
  36. short        *itemHit;
  37. {
  38.         Boolean    FilterValue;                                                /* Temporary return value */
  39.         Rect    tempRect;                                                     /* Temporary rectangle */
  40.         short    DType;                                                         /* Type of dialog item */
  41.         Handle    DItem;                                                        /* Handle to the dialog item */
  42.         ControlHandle    CItem;                                               /* Control handle */
  43.         short    chCode;                                                        /* Key entered */
  44.         long    LTemp;                                                         /* Used for time delay and HotSpot definitions */
  45.  
  46.         FilterValue = FALSE;
  47.         if (FirstTime == TRUE)                                               /* Make all controls and do lines and rects */
  48.             {
  49.                 GetDItem(theDialog,Res_Alrt_ReEnter,&DType,&DItem,&tempRect);/* Get the item handle */
  50.                 PenSize(3, 3);                                                  /* Change pen to draw thick default outline */
  51.                 InsetRect(&tempRect, -4, -4);                               /* Draw outside the button by 1 pixel */
  52.                 FrameRoundRect(&tempRect, 16, 16);                      /* Draw the outline */
  53.                 PenSize(1, 1);                                                  /* Restore the pen size to the default value */
  54.  
  55.                 FirstTime = FALSE;                                             /* Not first time anymore */
  56.             }
  57.  
  58.         FilterValue = Filter_Life_Alert(theDialog, theEvent, itemHit);/* Call the user routine */
  59.  
  60.         if (theEvent->what == keyDown)
  61.             {
  62.                 chCode =  (theEvent->message & charCodeMask);/* Get character */
  63.                 if ((chCode == 13) || (chCode == 0x03))                     /* CR or Enter */
  64.                     {
  65.                         FilterValue = TRUE;                                      /* Flag we got a hit */
  66.                         *itemHit = 1;                                             /* Default for CR */
  67.                         GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
  68.                         if (DType == (ctrlItem + btnCtrl))                     /* If a button then ... */
  69.                             {
  70.                                 CItem = (ControlHandle) DItem;                 /* Make it a controlhandle */
  71.                                 HiliteControl(CItem, 10);                         /* Hilite it */
  72.                                 LTemp = TickCount() + 15;                       /* Flash the button for 1/4 second */
  73.                                 do
  74.                                 {}
  75.                                 while (LTemp > TickCount());
  76.                                 HiliteControl(CItem, 0);                          /* UnHilite it */
  77.                             }
  78.                     }
  79.             }
  80.  
  81.         return(FilterValue);
  82. }
  83.  
  84.  
  85. /* ======================================================= */
  86.  
  87. void I_PA_Life_Alert()
  88. {
  89.  
  90.  
  91.         A_Init_Life_Alert();
  92.  
  93. }                                                                                /* End of procedure */
  94.  
  95.  
  96. /* ======================================================= */
  97.  
  98. void PA_Life_Alert()
  99. {
  100.         short    itemHit;                                                       /* Get the selection ID in here */
  101.         AlertTHndl    AlertResHandle;                                       /* Resource handle for Alert */
  102.         Rect    tempRect;                                                     /* Temp rect for moving the alert */
  103.  
  104.  
  105.         AlertResHandle = (AlertTHndl)GetResource('ALRT', Res_A_Life_Alert);/* Get the Alerts resource template handle */
  106.         HLock((Handle)AlertResHandle);                                    /* Lock the resource down while we use it */
  107.         tempRect = (*AlertResHandle)->boundsRect;                     /* Get the alerts position and size */
  108.         tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;/* Center Horz */
  109.         tempRect.bottom = tempRect.top + ((*AlertResHandle)->boundsRect.bottom - (*AlertResHandle)->boundsRect.top);
  110.         tempRect.right = tempRect.left + ((*AlertResHandle)->boundsRect.right - (*AlertResHandle)->boundsRect.left);
  111.         (*AlertResHandle)->boundsRect = tempRect;                     /* Place the centered position back in the template */
  112.  
  113.         FirstTime = TRUE;                                                     /* Set the flag for the filter proc */
  114.  
  115.         /* Let the OS handle the Alert and wait for a result to be returned */
  116.         itemHit = NoteAlert(Res_A_Life_Alert, &MyFilter);           /* Bring in the alert resource */
  117.         HUnlock((Handle)AlertResHandle);                                 /* Release the alert handle to float */
  118.  
  119.         /* This is the default selection, when RETURN is pressed. */
  120.         if (Res_Alrt_ReEnter == itemHit)                                  /* See if this Button was selected */
  121.             {
  122.             }
  123.  
  124.  
  125.         A_Hit_Life_Alert(itemHit);                                         /* Tell the user routine which item was selected */
  126.  
  127.  
  128. }                                                                                /* End of procedure */
  129.  
  130.